package com.xuesinuo.ots.config.i18n;

import java.text.MessageFormat;
import java.util.LinkedHashMap;
import java.util.Map;

import com.xuesinuo.xtool.Np;

/**
 * 各语言提示语
 * 
 * @author xuesinuo
 */
public enum I18nTips {
    captcha_error("验证码错误", "Captcha error"),
    cant_operate_yourself("不可以操作自己", "Can't operate yourself"),
    no_auth("无权限", "No permission"),
    login_first("请先登录", "Please login first"),
    export_invoice_pfd_error("导出InvoicePDF失败", "Export invoice PDF failed"),
    username_exist("用户名已存在", "Username exist"),
    old_password_error("旧密码错误", "Old password error"),
    username_password_error("用户名或密码错误", "Username or password error"),
    user_disabled("用户已停用", "User is disabled"),
    user_not_found("用户不存在", "User not found"),
    user_username_exist("用户名已存在", "Username exist"),
    user_code_exist("用户编码已存在", "User code exist"),
    has_user_cant_delete_role("有{0}个用户是当前角色，不可删除", "There are {0} users with the current role, can't delete"),
    password_size("密码长度必须为8-20位", "Password length must be 8-20"),
    password_format("密码中必须包含【大写字母】、【小写字母】、【数字】至少各1个", "Password must contain at least 1 uppercase letter, 1 lowercase letter, and 1 number"),
    password_cant_same("密码中不能连续出现相同的字符", "Password can't contain the same character in a row"),
    password_cant_consecutive("密码中不能连续出现连续的字符", "Password can't contain consecutive characters"),
    export_excel_max("导出Excel最大支持{0}条数据", "Export Excel supports up to {0} data"),
    username_can_not_empty("用户名不能为空", "Username can't be empty"),
    ;

    private Map<I18nLanguage, String> lang2Tip;

    /**
     * 构造方法顺序参考{@link I18nLanguage}
     * 
     * @param tips 提示语
     */
    private I18nTips(String... tips) {
        lang2Tip = new LinkedHashMap<>();
        for (int i = 0; i < I18nLanguage.values().length; i++) {
            I18nLanguage lang = I18nLanguage.values()[i];
            String tip = tips.length > i ? Np.i(tips[i]).o("") : "";
            lang2Tip.put(lang, tip);
        }
    }

    /**
     * 获取Tip提示语
     * 
     * @param i18nLanguage 语言
     * @param args         占位符变量
     * @return 提示语
     */
    public String getTip(I18nLanguage i18nLanguage, Object... args) {
        return MessageFormat.format(lang2Tip.get(i18nLanguage), args);
    }
}
